package script;
import data.loginData;
import org.openqa.selenium.*;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import tools.UseBrowser;
import vo.LoginPage; // 使用PO模型
import java.io.IOException;
import java.net.MalformedURLException;
import static org.testng.Assert.assertEquals;

import data.loginData.*;

public class PO_OSChina_Login_local extends UseBrowser {
    //osc_Login oscl = new osc_Login();
    LoginPage lp = new LoginPage();  // 使用po模型
    UseBrowser ub1 = new UseBrowser();
    WebDriver wd;
    @BeforeTest
    public void beforeTest() throws IOException {
        // wd=ub1.setupOpera();
        wd = ub1.setupChrome();
        //wd=ub1.setupFirfox();
    }
//    @DataProvider(name = "login_data")
//    public static Object[][] login_data() {
//        return new Object[][]{
//                {"James", "james9437974", "用户名或密码错误123", "hellotest1"},
//                {"jamesz2011@126.com", "", "密码不能为空", "hellotest2"},
//                {"", "james9437974", "用户名不能为空", "hellotest3"},
//                {"", "", "用户名不能为空", "hellotest4"},
//                {"jamesz2011@126.com", "james9437974", "", "hellotest5"},
//        };
//    }

    // dataProviderClass:进行外部dataProvider的导入
    @Test(dataProvider = "login_data", dataProviderClass = loginData.class)
    public void OSC_Login1(String Username, String Password, String exp, String hellotest) throws MalformedURLException, InterruptedException {
        System.out.println("my hellotest:----->" + "open1");
        wd.get("http://www.oschina.net/");
        System.out.println("my hellotest:----->" + "open2");
        //wd.findElement(By.linkText("登录")).click();
        LoginPage login = PageFactory.initElements(wd, LoginPage.class);
        login.click_loginlink();
        login.click_passwordLoginTab();
        login.input_login_data(Username, Password);
        WebElement savebox = wd.findElement(By.xpath(lp.savebox));
        boolean flag = savebox.isEnabled();
        boolean flag1 = true;
        login.click_savebox();
        login.click_loginbutton();
        System.out.println("start-test");

        Thread.sleep(2000);
//        if (isPresentEle(By.xpath(login.NoPasswd), wd)) {
//            System.out.println("-------------");
//            System.out.println("密码为空");
//            System.out.println("-------------");
//        } else if (isPresentEle(By.xpath(login.NoUsername), wd)) {
//            System.out.println("-------------");
//            System.out.println("用户名为空");
//            System.out.println("-------------");
//        } else if (isPresentEle(By.xpath(login.NoUsername_Passwd), wd)) {
//            System.out.println("-------------");
//            System.out.println("用户名、密码均为空");
//            System.out.println("-------------");
//        } else if (isPresentEle(By.xpath(login.Wrong_Username_Password), wd)) {
//            WebElement Wrong_Username_Password = wd.findElement(By.xpath(login.Wrong_Username_Password));
//            String W_U_P = Wrong_Username_Password.getText();
//            System.out.println("-------------");
//            System.out.println("用户名或密码错误");
//            if (W_U_P.equals(exp)) {
//                System.out.println("用户名或密码错误-----ok");
//            } else {
//                System.out.println("用户名或密码错误-----error");
//                takeScreenshot(wd);
//                takeScreenshot(wd);
//            }
//            System.out.println("-------------");
//        } else if (isPresentEle(By.xpath(login.Rigit_Username_Password), wd)) {
//            System.out.println("-------------");
//            System.out.println("用户名与密码正确");
//            System.out.println("-------------");
//            System.out.println("666");
//        }
    }
    @AfterClass
    public void closebrowser() {
        wd.quit();
    }
}